<template>
    <div class="container">
      <div class="login-box">
        <!-- <div class="avatar">
          <img src="../assets/logo.png" alt>
        </div> -->
        <!-- <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="70px"
          class="demo-ruleForm"
        >
          <el-form-item label="用户名" prop="username">
            <el-input v-model="ruleForm.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="ruleForm.password" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login('ruleForm')">登陆</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form> -->
      </div>
    </div>
</template>
<script>
import { login_api } from "@/api";
export default {
  data() {
    return {
      ruleForm: {
        username: "admin",
        password: "123456"
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 1, max: 5, message: "长度在 1 到 5 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 6, message: "长度在 3 到 6个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    login(formName) {
      this.$refs[formName].validate(async valid => {
        if (!valid) return this.$message.error("信息有误！");
        const { data: res } = await login_api(this.ruleForm);
        // if(res.meta.status!=200)return this.$message.error('登陆失败！')
        sessionStorage.setItem("token", res.data.token);
        this.$message.success("登陆成功！");
        this.$router.push("/home");
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>
<style lang="less" scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  // position: relative;
  height: 100%;
  width: 100%;
  background-color: rgb(42, 49, 104);
  .login-box {
    // position: absolute;
    // top: 50%;
    // left: 50%;
    // transform: translate(-50%, -50%);
    width: 450px;
    height: 300px;
    background-color: #fff;
    // .el-form {
    //   width: 100%;
    //   box-sizing: border-box;
    //   padding: 0 20px;
    //   position: absolute;
    //   bottom: 0;
    //   .el-form-item__label {
    //     text-align: left;
    //   }
    // }
    // .avatar {
    //   position: absolute;
    //   top: 0;
    //   left: 50%;
    //   transform: translate(-50%, -50%);
    //   width: 130px;
    //   height: 130px;
    //   padding: 10px;
    //   overflow: hidden;
    //   border: 1px solid #eee;
    //   box-shadow: 0 0 10px #fff;
    //   border-radius: 50%;
    //   background-color: #fff;
    //   img {
    //     width: 100%;
    //     border-radius: 50%;
    //     background-color: #eee;
    //   }
    // }
  }
}
</style>

